<template>
  <div>
    <el-table
      v-loading="load"
      :data="list.length === 0 ? otherList : list"
      :highlight-current-row="highlightCurrentRow"
      :show-summary="showSummary"
      :summary-method="summaryMethod"
      :header-cell-class-name="headerCellClassName"
      :cell-style="cellStyle"
      stripe
      border
      cell-class-name="table-row"
      @selection-change="handleSelectionChangecheck"
      @current-change="handleSelectionChange"
      @cell-click="myCellClick"
    >
      <slot/>
    </el-table>

    <br>
    <!-- 分页
    <Pagination
      :data="page"
      @change-size="handleSizeChange"
      @change-page="handleCurrentChange"
    />-->
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import _ from 'lodash'

export default {
  name: 'BaseTable',
  components: {
    Pagination
  },
  props: {
    highlightCurrentRow: {
      type: Boolean,
      default: false
    },
    showSummary: {
      type: Boolean,
      default: false
    },
    cellStyle: {
      type: Object,
      default() {
        return {}
      }
    },
    summaryMethod: Object,
    otherList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      list: [],
      page: {},
      load: false
    }
  },
  methods: {
    headerCellClassName() {
      return 'baseTableNoPage'
    },
    filData(data) {
      this.list = data
      // this.page = data
      return this
    },
    wait() {
      this.load = true
      return this
    },
    complete() {
      this.load = false
      return this
    },
    //   handleSizeChange(size) {
    //     this.$emit('chaneg-size', this, size)
    //   },
    //   handleCurrentChange(current) {
    //     this.$emit('chaneg-page', this, current)
    //   },
    handleSelectionChange(val) {
      this.$emit('current-change', val)
    },
    handleSelectionChangecheck(val) {
      this.$emit('selection-change', val)
    },
    push(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'id')
    },
    editpush(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'ORGDEPT_ID')
    },
    rolePush(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'ROLE_ID')
    },
    dealerPush(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'DEALER_ID')
    },
    AuthPush(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'POSITION_ID')
    },
    partFrotPush(data) {
      if (!data) return
      this.list = this.list.concat(data)
      this.list = _.uniqBy(this.list, 'PART_ID')
    },
    delete(index) {
      this.list.splice(index, 1)
    },
    data() {
      return this.list
    },
    clearData() {
      return (this.list = [])
    },
    myCellClick(row, column, cell, event) {
      this.$emit('cell-click', row, column, cell, event)
    },
    getData() {
      return this.list
    }
  }
}
</script>

<style scoped>
</style>
